export const editMixin = {
  data() {
    return {
      model: {
      	id: undefined
      },
	  btnText: "添加",
      //数据校验规则
      rules: {}
    };
  },
  onLoad(params){
  	if (params.id && params.id != 'undefined'){
		this.btnText = "编辑";
  		//如果是编辑获取数据
  		this.callFindById(params.id).then(res => {
  			this.model = Object.assign({}, res.data);
  		});
  	}
  },
  onReady() {
	if(this.$refs.uForm)  
		this.$refs.uForm.setRules(this.rules);
  },
  methods: {
    //提交表单
    submit() {
		this.$refs.uForm.validate(valid => {
			if (valid) {
				let model = Object.assign({}, this.model); // copy obj
				this.callSave(model).then(res => {
					uni.showToast({
					    title: "保存成功！",
					    icon: "success",
					    duration: 2000,
						success: function () {
							uni.setStorageSync("isRefresh",1);
							uni.navigateBack();
						}
					});
				});
			} else {
				this.$u.toast('您填写的信息有误，请根据提示修正。');
			}
		});
    },
	cancel() {
		uni.navigateBack();
	}	
  }
};
